home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Magazine / Online / httpproxy / changeinstall.rexx < prev    next >
OS/2 REXX Batch file  |  1996-08-20  |  2KB  |  74 lines

  1. /* Change one line in a configuration file, add it when it is not already there. */
  2. /* Usage: rx changeinstall.rexx File/A //-Text-//Str1 Str2 Str3 */
  3.  
  4. /*
  5.  * A copy of every 'file' is made into 'file.rexxbackup'.
  6.  *
  7.  * The first line that contains all Strs will be replaced by Text.
  8.  * When no line is found that contains all Strs, the line is added to the end of the file.
  9.  *
  10.  * When a write fails or the ending statement is missing, the backup file
  11.  * is restored and the script returns 20.
  12.  */
  13.  
  14. parse arg File pad "---" Text "---" rest
  15. parse var rest Str1 Str2 Str3
  16. address command
  17.  
  18. if ~exists(File) then
  19.    exit 20
  20.  
  21. if Str1 == "" then
  22.    exit 20
  23. if Str2 == "" then
  24.    Str2 = Str1
  25. if Str3 == "" then
  26.    Str3 = Str2
  27.  
  28. "delete >nil: "File".rexxbackup"
  29. "rename "File File".rexxbackup"
  30. if (open("r",File".rexxbackup","READ") ~= 1) then
  31. do
  32.    say "Reading file "File" failed..."
  33.    "rename "File".rexxbackup "File   /* and rename back... */
  34.    exit 20
  35. end
  36. if (open("w",File,"WRITE") ~= 1) then
  37. do
  38.    say "Writing to file "File" failed..."
  39.    "rename "File".rexxbackup "File   /* and rename back... */
  40.    exit 20
  41. end
  42. if (open("f","env:_httpproxy_files","APPEND") ~= 1) then
  43.    exit 20
  44. call writeln("f",File": "Text)
  45. call close("f")
  46.  
  47. added = 0
  48. do while (eof("r") = 0)
  49.    line = readln("r")
  50.    if (line == "" & eof("r") = 1) then
  51.       leave
  52.    if (InExp(line)) then
  53.    do
  54.       added = 1
  55.       call writeln("w",Text)
  56.    end
  57.    else
  58.       call writeln("w",line)
  59. end
  60. if ((~ added) & (Text ~== "")) then
  61.    call writeln("w",Text)
  62.  
  63. call close("r")
  64. call close("w")
  65.  
  66. exit 0
  67.  
  68. InExp: procedure expose Str1 Str2 Str3
  69.    parse Arg n
  70.    if (index(n,Str1) ~= 0 & index(n,Str2) ~= 0 & index(n,Str3) ~= 0) then
  71.       return 1
  72.    return 0
  73.  
  74.